<?php

namespace Common\Model;

class OrderUserModel extends BaseModel {

    protected $trueTableName = 'tb_order_user';

    /**
     * 获取信息
     * @param integer $id ID
     * @return type
     */
    public function getInfoById($id, $returnDeleted = true) {
        $option = [
            'id'=> $id,
        ];
        if(!$returnDeleted)
        {
            $option['isdelete'] = 0;
        }
        $data = $this->field('*')->where($option)->find();        
        return empty($data) ? array() : $data;
    }
    
    public function getListByOrderInfoId($orderInfoId, $onlyShareUser = true)
    {
        $option = [
            'orderinfo_id'=> $orderInfoId,
            'isdelete' => 0,
        ];
        if($onlyShareUser)
        {
            $option['isshareuser'] = 1;
        }
        $data = $this->field('*')->where($option)->select();
        return empty($data) ? array() : $data;
    }    

    public function getListByIds($orderUserIds)
    {
        if(empty($orderUserIds)||!is_array($orderUserIds))
        {
            return array();
        }
        $option = [
            'id'=> array('in', $orderUserIds),
            'isdelete' => 0,
            'isshareuser' => 1,
        ];
        $data = $this->field('*')->where($option)->select();
        return empty($data) ? array() : $data;
    }

    public function addInfo($data)
    {
        return $this->add($data);
    }
    
    public function updateInfo($data, $where)
    {
        return $this->where($where)->data($data)->save();
    }
}
